﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Samples.ServiceHosting.StorageClient;
using System.Globalization;
using System.Collections.Specialized;

namespace Ciripescu_WebRole.BL
{
    public class CBlobStorage
    {

        #region Public Methods
        public CBlobStorage()
        {
            m_blobStorage  = BlobStorage.Create(StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration());
            m_blobCntainer = m_blobStorage.GetBlobContainer("ciripescucontainer");//container name 
        }

        public void SaveImage(string id, string contentType, byte[] data)
        {
            BlobProperties properties = new BlobProperties(id);
            properties.ContentType    = contentType;
            BlobContents imageBlob    = new BlobContents(data);

            m_blobCntainer.CreateBlob(properties, imageBlob, true);
        }

        public BlobProperties GetImage(string id)
        {
            return m_blobCntainer.GetBlobProperties(id);
            
        }

        public bool DeleteImage(string id)
        {
            bool ok = true;
            if (m_blobCntainer.DoesBlobExist(id))
                m_blobCntainer.DeleteBlob(id);
            else
                ok = false;

            return ok;
        }

        #endregion

        #region Private Methods
            private BlobStorage   m_blobStorage;
            private BlobContainer m_blobCntainer;
        #endregion
    }

    
}
